﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Admin_Maintenance : System.Web.UI.Page
{
    MaintenanceBLL maintenanceLogic = new MaintenanceBLL();
    protected string Mode
    {
        get
        {
            return (string)ViewState["Mode"];
        }
        set
        {
            ViewState["Mode"] = value;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void btnOpenGlobal_Click(object sender, EventArgs e)
    {
        Mode = "Application";
        lblMeintenanceType.Text = "Application Wide";
        LoadSettings();
        PanelMaintenance.Visible = true;
    }

    protected void btnOpenClass_Click(object sender, EventArgs e)
    {
        Mode = "ClassPopup";
        lblMeintenanceType.Text = "Class Page";
        LoadSettings();
        PanelMaintenance.Visible = true;
    }

    private void LoadSettings()
    {
        Maintenance.MaintenanceRow maintenance = maintenanceLogic.GetMaintenance(Mode);
        txtMaintenance.Value = maintenance.Message;
        chkboxEnabled.Checked = maintenance.IsEnabled;
    }

    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        bool result = maintenanceLogic.UpdateMaintenance(txtMaintenance.Value, chkboxEnabled.Checked, Mode);
        if (result)
        {
            // *SteveMsg
            string modalPopupMsg = "Maintenance Message has been updated.";
            ModalPopupMessage.ShowModalPopup("ILE Message", modalPopupMsg, 1);
        }
        else
        {
            // *SteveMsg
            string modalPopupMsg = "Error occured while updating Maintenance Message.";
            ModalPopupMessage.ShowModalPopup("ILE Message", modalPopupMsg, 2);
        }
    }

}
